package cn.stylefeng.guns.modular.inventory.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.inventory.entity.MoveDiskDetailed;
import cn.stylefeng.guns.modular.inventory.mapper.MoveDiskDetailedMapper;
import cn.stylefeng.guns.modular.inventory.model.params.MoveDiskDetailedParam;
import cn.stylefeng.guns.modular.inventory.model.result.MoveDiskDetailedResult;
import cn.stylefeng.guns.modular.inventory.service.MoveDiskDetailedService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 动盘明细表 服务实现类
 * </p>
 *
 * @author hu
 * @since 2019-08-08
 */
@Service
public class MoveDiskDetailedServiceImpl extends ServiceImpl<MoveDiskDetailedMapper, MoveDiskDetailed> implements MoveDiskDetailedService {


    @Override
    public void add(MoveDiskDetailedParam param){
        MoveDiskDetailed entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(MoveDiskDetailedParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(MoveDiskDetailedParam param){
        MoveDiskDetailed oldEntity = getOldEntity(param);
        MoveDiskDetailed newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public MoveDiskDetailedResult findBySpec(MoveDiskDetailedParam param){
        return this.baseMapper.findBySpec(param);
    }

    @Override
    public List<MoveDiskDetailedResult> findListBySpec(MoveDiskDetailedParam param){
        return this.baseMapper.findListBySpec(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(MoveDiskDetailedParam param,String condition,Long deptId,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition,deptId, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public LayuiPageInfo deleteList(MoveDiskDetailedParam moveDiskDetailedParam, String condition,Long deptId) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.deleteList(pageContext, moveDiskDetailedParam,condition,deptId);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public List<MoveDiskDetailedResult> historyDetailedList(MoveDiskDetailedParam moveDiskDetailedParam) {
        return this.baseMapper.historyDetailedList(moveDiskDetailedParam);
    }

    @Override
    public List<MoveDiskDetailedResult> findByDetailedList(MoveDiskDetailedParam moveDiskDetailedParam) {
        return this.baseMapper.findByDetailed(moveDiskDetailedParam);
    }


    @Override
    public List<MoveDiskDetailedResult> findPositionList(MoveDiskDetailedParam param) {
        return this.baseMapper.findPositionList(param);
    }

    @Override
    public LayuiPageInfo abnormalList(MoveDiskDetailedParam param) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.abnormalList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public List<MoveDiskDetailedResult> spreadList(MoveDiskDetailedParam stockParam) {
        return this.baseMapper.spreadList(stockParam);
    }

    private Serializable getKey(MoveDiskDetailedParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private MoveDiskDetailed getOldEntity(MoveDiskDetailedParam param) {
        return this.getById(getKey(param));
    }

    private MoveDiskDetailed getEntity(MoveDiskDetailedParam param) {
        MoveDiskDetailed entity = new MoveDiskDetailed();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

	@Override
	public LayuiPageInfo querylistPageBySpec(MoveDiskDetailedParam moveDiskDetailedParam, String condition) {
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.querylistPageBySpec(pageContext, moveDiskDetailedParam,condition);
        return LayuiPageFactory.createPageInfo(page);
	}

    @Override
    public List<MoveDiskDetailedResult> findListByDiskDetailed(MoveDiskDetailedParam param) {
        return this.baseMapper.findListByDiskDetailed(param);
    }

	@Override
	public List<MoveDiskDetailedResult> appabnormalliststaylist(MoveDiskDetailedParam param,Long deptId) {
        return this.baseMapper.appabnormalliststaylist(param, deptId);
	}


}
